﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;

namespace ShaderLab
{
    class DirectionalLight
    {

        #region Light Properties
        Color color;
        public Color Color
        {
            get { return color; }
            set { 
                color = value;
                structColor.SetValue(color.ToVector3());
            }
        }

        Vector3 direction;
        public Vector3 Direction
        {
            get { return direction; }
            set { 
                direction = value;
                structDirection.SetValue(direction);
            }
        }
        #endregion


        #region Effect
        Effect effect;

        EffectParameter structInstance;

        EffectParameter structColor;

        EffectParameter structDirection;
        #endregion


        #region Initialization
        public DirectionalLight(Effect effect)
        {
            this.effect = effect;
            structInstance = effect.Parameters["DirectionalLight"];
            structColor = structInstance.StructureMembers["Color"];
            structDirection = structInstance.StructureMembers["Direction"];

            Color = Color.Black;

            Vector3 d = Vector3.One;
            d.Normalize();
            Direction = d;
        }
        #endregion


        public void UpdateLight()
        {
            structColor.SetValue(color.ToVector3());
            structDirection.SetValue(direction);
        }
    }
}
